package com.djl.zenithbite.controller.shopping;

import com.djl.zenithbite.common.response.BaseResponse;
import com.djl.zenithbite.entity.ProductCategory;
import com.djl.zenithbite.entity.ProductCategoryExample;
import com.djl.zenithbite.repository.ProductCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/product/category")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryMapper productCategoryMapper;

    @PostMapping("/add")
    BaseResponse<ProductCategory> add(ProductCategory productCategory){
        productCategory.setCreatedAt(new Date());
        productCategory.setUpdatedAt(new Date());
        productCategoryMapper.insertSelective(productCategory);

        BaseResponse<ProductCategory> response = new BaseResponse<>();
        response.setCode(BaseResponse.SUCCESS);
        response.setData(productCategory);
        return response;
    }

    @GetMapping("/list")
    BaseResponse<List<ProductCategory>> list(){
        BaseResponse<List<ProductCategory>> response = new BaseResponse<>();
        response.setCode(BaseResponse.SUCCESS);
        response.setData(productCategoryMapper.selectByExample(new ProductCategoryExample()));
        return response;
    }
}
